﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

using CE.User;
using CE.Global;
using CE.Provider;

public partial class Provider_CarInsurance_ViewCarUsage : System.Web.UI.Page
{
    string PageName = "CXCI";
    string SubPageName = "CXCICUSE";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session[CE.Global.General.UserId] == null || Session[CE.Global.General.ProviderCompanyId] == null)
        {
            Response.Redirect("~/Provider/ProviderSecureLogin.aspx");
        }
        CheckMainPageAccess();
        CheckSubPageAccess();

        if (!IsPostBack)
        {
            LoadCarUsageList();
        }
    }

    protected void grvCarUsage_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (grvCarUsage.Rows.Count > 0)
        {
            string strCUID = grvCarUsage.SelectedDataKey.Values[0].ToString();
            Response.Redirect("ProviderCarUsage.aspx?CUID=" + strCUID);
        }
    }

    public void LoadCarUsageList()
    {
        CarUsageDB _carusagedb = new CarUsageDB();
        grvCarUsage.DataSource = _carusagedb.GetProviderCarUsageList(Convert.ToInt64(Session[CE.Global.General.ProviderCompanyId]));
        grvCarUsage.DataBind();
    }

    protected void ibtBack_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("~/Provider/CarInsurance/TableMatching.aspx");
    }

    private void CheckMainPageAccess()
    {
        Int64 PageAccess = General.GetProviderMainPageAccess(Convert.ToInt64(Session[General.ProviderCompanyId].ToString()),
                                                        Convert.ToInt64(Session[General.UserId].ToString()), PageName);
        if (PageAccess == 0)
        {
            //Response.Redirect("~/Provider/UserMessage.aspx?errorcode=2000");
            Response.Redirect("~/Provider/UserMessage.aspx?mt=UM&ec=2000");
        }
    }

    private void CheckSubPageAccess()
    {
        Int64 PageAccess = General.GetProviderSubPageAccess(Convert.ToInt64(Session[General.ProviderCompanyId].ToString()),
                                                        Convert.ToInt64(Session[General.UserId].ToString()), SubPageName);
        if (PageAccess == 0)
        {
            //Response.Redirect("~/Provider/UserMessage.aspx?errorcode=2000");
            Response.Redirect("~/Provider/UserMessage.aspx?mt=UM&ec=2000");
        }
        else if (PageAccess == 100)
        {
            lnkNewCarUsage.Visible = false;
        }
    }

}
